<template>
  <div>
    <table-ext :columns="columns2" :searchForm="searchForm2" :config="config2" ref="tableExt2">
      <template slot="table-action">
          <el-button type="primary" icon="el-icon-plus" @click="addRfi">新增</el-button>
      </template>
    </table-ext>
  </div>
</template>
<script>
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  export default {
    // 引入自定义表格组件
    components:{
      'table-ext': TableExt
    },
    data() {
      return {
        // 弹框属性
        addOrUpdateForm: {
          abolishReason: ''
        },
        // 弹框显示控制
        dialogFormVisible: false,
        // 修改弹框控制
        dialogUpdate: false,    
        config2:{ 
          title: 'RFI', //页面标题
          isPage: true, //是否分页
          isNo: true, //是否显示序号
          selection: true, //是否显示复选框
          crudMapping:{ // CRUD方法
            query:{
              url: this.lib.config.host.vendorMgt + '/vendormgt/vsp/rfi/query',
              method: 'securityPost'
            },
            delete: {
              url: this.lib.config.host.vendorMgt + '/vendormgt/vsp/rfi/delete',
              method: 'securityPost'
            },
            publish: {
              url: this.lib.config.host.vendorMgt + '/vendormgt/vsp/rfi/publish',
              method: 'securityPost'
            }
          }
        },
        
         // 查询表单配置
        searchForm2:[{ // 查询表单配置
          label: '采购组织', 
          key: 'purOrgId', 
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/system/purOrgMgt/purOrg/getPurOrgByUserId/' + this.getCurrUserId(),
            method:'get',
            label:'purOrgName',
            value:'id'
          }
        }, {
          label: '采购组',
          key: 'purGroupId',
          type: 'select',
          dict:{
            url:this.lib.config.host.masterData + '/mdata/purOrgMgt/purGroup/getByPurOrgId/{purOrgId}',
            method:'post',
            label:'purGroupName',
            value:'id'
          }
        },{
          label: 'RFI编码',
          key: 'rfiCode',
          type: 'input'
        },{
          label: '标题',
          key: 'title',
          type: 'input'
        },{
          label: '类型',
          key: 'infoType',
          type: 'select',
          dict: [{
            value: 'rfi2',
            label: '产品认证'
          },{
            value: 'rfi3',
            label: '调查问卷'
          }]
        },{
          label: '发布状态',
          key: 'publishStatus',
          type: 'select',
          dict: [{
            value: '0',
            label: '未发布'
          }, {
            value: '1',
            label: '已发布'
          }]
        },{
          label: '审核状态',
          key: 'checkStatus',
          type: 'select',
          dict: [
          {
            value: '1',
            label: '已审核'
          }, {
            value: '0',
            label: '未审核'
          },
          {
            value: '2',
            label: '部分审核'
          }
          ]
        },{
          label: '反馈状态',
          key: 'feedbackStatus',
          type: 'select',
          dict: [
          {
            value: '1',
            label: '已反馈'
          }, {
            value: '0',
            label: '未反馈'
          },
          {
            value: '2',
            label: '部分反馈'
          }
          ]
        }],
        
        columns2:[{ 
          label: 'RFI编码', // 表格header
          width: '160',
          render:(createElement, params)=>{ // 动态渲染，click事件示例
            let _this = this;
            if(params.row.publishStatus == 1){
              return createElement('div', {}, [createElement('a', {
                style: {
                  color: '#409EFF',
                  cursor: 'pointer'
                },
                  on: {
                    click() {
                      _this.toView(params.row.id);
                    }
                  }
                }, params.row.rfiCode)
              ]);
            }else{
              return createElement('div', {}, [createElement('a', {
                style: {
                  color: '#409EFF',
                  cursor: 'pointer'
                },
                  on: {
                    click() {
                      _this.toEdit(params.row.id);
                    }
                  }
                }, params.row.rfiCode)
              ]);
            } 
          }
        },{
          label: '采购组织',
          key: 'purOrgName',
          width: '160'
        },{
          label: '采购组',
          key: 'purGroupName',
          width: '120'
        },{
          label: '标题',
          key: 'title',
          width: '200'
        },{
          label: 'RFI类型',
          key: 'infoTypeName',
          width: '130'
        },{
          label: '发布状态',
          key: 'publishStatus',
          width: '90',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.publishStatus,
                titles: [{status:0,title:'未发布'},{status:1,title:'已发布'}]
            }});
          }
        },{
          label: '发布日期',
          key: 'publishTime',
          width: '110'
        },{
          label: '发布人',
          key: 'publishUserName',
           width: '120'
        },{
          label: '反馈状态',
          key: 'feedbackStatus',
          width: '90',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.feedbackStatus,
                titles: [{status:0,title:'未反馈'},{status:1,title:'已反馈'}]
            }});
          }
        },{
          label: '审核状态',
          key: 'checkStatus',
          align: 'center',
          render:(createElement, params)=>{ //动态渲染, 字典表示例
            return createElement(TableIcon,{props:{
                flag: params.row.checkStatus,
                titles: [{status:0,title:'未审核'},{status:1,title:'已审核'},{status:3,title:'待审核'},{status:-1,title:'驳回'}]
            }});
          }
        }
        ]
      };
    },
    mounted() {
    },
    methods: {
      addRfi(){
        this.$router.push('/Index/Supplier/RfiAdd');
      },
      toView(id) {
         window.open('/Rfi/Buyer/View/RfiDeail?rfiId='+ id)
      },
      toEdit(id) {
        this.$router.push('/Index/Supplier/RfiAdd?rfiId=' + id);
      }
    }
  }
</script>
